package vue;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;

import java.util.Vector;

import modele.Cadre;


public class VueCadre {
    
    private Cadre leCadre;
    private Vector lesVueElements = new Vector();
    private int height;
    private int width;
    private Color color;

    public VueCadre(Cadre leCadre, int height, int width) {
        super();
        this.leCadre = leCadre;
        this.height = height;
        this.width = width;
        this.color =  new Color(0, 0, 0);
    }

    public void Dessiner(Graphics g) {
        g.setColor(new Color(0, 0, 0));
        g.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
        for (int i = 0; i < lesVueElements.size(); i++) {
            VueElement vB = (VueElement) lesVueElements.elementAt(i);
            vB.Dessiner(g);
        }

        return;
    }     
    
    public VueElement SelectElement(int x, int y) {
        VueElement vEReturn = null;
        for (int i = 0; i < lesVueElements.size(); i++) {
            VueElement vE = (VueElement) lesVueElements.elementAt(i);
            vE.setSelected(false);
            if (vE.isClicked(x, y)) {
                vE.setSelected(true);
                vEReturn = vE;
            }
        }
        return vEReturn;
    }

    public void SupprimerElementsSelectionnee() {
        for (int i = 0; i < lesVueElements.size(); i++) {
            VueElement vE = (VueElement) lesVueElements.elementAt(i);
            if (vE.getSelected()) {
                lesVueElements.remove(i);
            }

        }
    }

    
    public void ChangerCouleurElementSelectionnee(Color nouvelleCouleur){
        for (int i = 0; i < lesVueElements.size(); i++) {
            VueElement vE = (VueElement) lesVueElements.elementAt(i);
            if (vE.getSelected()) {
               vE.setSelected(false);
            }

        }
       
    }
    
    public void ajouterVueElement(VueElement vueElement){
        this.lesVueElements.add(vueElement);
        return;
    }
    
    public void supprimerVueElement(VueElement vueElement){
        this.lesVueElements.remove(vueElement);
        return;
    }
    
    public Point ConvertirEnPixel(Point lePointEnMetre) {
        Point lePointResultat = new Point();
        lePointResultat.x = (int) lePointEnMetre.getX() * width / leCadre.getWidth();
        lePointResultat.y = (int) lePointEnMetre.getY() * height / leCadre.getHeight();
        return lePointResultat;
    }
    
    public VueCadre() {
        super();
    }


    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public Color getColor() {
        return color;
    }

    public void setColor(Color color) {
        this.color = color;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public void setLeCadre(Cadre leCadre) {
        this.leCadre = leCadre;
    }

    public Cadre getLeCadre() {
        return leCadre;
    }

    public Vector getLesVueElements() {
        return lesVueElements;
    }
}
